#include "CenterScene.h"

#define RegRpc(fun) STATIC_RUN( RpcNetSvr<CRpcConToClient>::Ins().RegFun(&CenterSceneMgr::fun, CenterSceneMgr::Ins(), #fun);) 

using namespace su;
using namespace std;
using namespace proto;

CenterSceneMgr& gCenterSceneMgr = CenterSceneMgr::Ins();

CScene* CenterSceneMgr::Find(uint32 sceneId, uint64 id)
{
	// unfinished , 临时固定一个场景先

	return &tmpScene;
	if (CScene::IsFb(sceneId))
	{
		auto it = m_id2Fb.find(id);
		if (it != m_id2Fb.end())
		{
			return &(it->second);
		}
	}
	else
	{
		auto it = m_cfgId2Scene.find(sceneId);
		if (it != m_cfgId2Scene.end())
		{
			return &(it->second);
		}
	}
	return nullptr;
}

RegRpc(CreateScene);
void CenterSceneMgr::CreateScene(uint32 cfgId, uint64 id)
{
	CRpcConToClient* con = gRpcSvr.GetCurCon();
	L_COND_V(SvrType::Zone == con->GetSvrType());

	CScene scene;
	scene.cfgId = cfgId;
	scene.id = id;
	scene.m_conZone = con->GetWeakPtr();
	if (scene.IsFb())
	{
		L_COND_V(m_id2Fb.insert({id, scene}).second);
	}
	else
	{
		L_COND_V(m_cfgId2Scene.insert({cfgId, scene}).second);
	}
}

RegRpc(DelScene);
void CenterSceneMgr::DelScene(uint32 cfgId, uint64 id)
{
	if (id != 0)
	{
		L_COND_V(m_id2Fb.erase(id) == 1);
	}
	else
	{
		L_COND_V(m_cfgId2Scene.erase(cfgId) == 1);
	}
}

bool CScene::IsFb()
{
	L_COND_F(false, "todo ,read from cfg");
	return false;
}

bool CScene::IsFb(uint32 cfgId)
{
	L_COND_F(false, "todo ,read from cfg");
	return false;
}
